package org.kfive.nova.io.nio;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;

/*
* FileLockTest.java
* Created  by  lizhanwu
* Created on 2016-5-19 15:03
*/
public class FileLockTest {

    public static void main(String[] args){

        FileLock fileLock = null;
        try {
            RandomAccessFile file = new RandomAccessFile("D:\\tmp\\datatype.xml","rw");
            FileChannel channel = file.getChannel();
            fileLock = channel.lock(0,Long.MAX_VALUE,false);
            System.out.println("is shared"+fileLock.isShared());
            Thread.sleep(10000);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                fileLock.release();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}
